<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>管理员信息</title>
<link rel="stylesheet" type="text/css" href="/css/save.css" />
<script src="/jquery/jquery.min.js"></script>
<script src="/utils/TimeUtil.js"></script>
<script src="/utils/HttpUtil.js"></script>
<script>
	var params = {};

	$(document).ready(function() {
		getInfo();
	});

	function init() {
		$("#msg").text("");
		$("#error_username").text("");
		$("#error_realname").text("");
		$("#error_email").text("");
		$("#error_phone").text("");
		$("#error_useStatus").text("");
	}

	function getInfo() {
		var urlId = getQueryString("id");
		if (urlId) {
			console.log("id=" + urlId);
			post("/admin/selectById", {
				id : urlId
			}, initInfo, err);
		}
	}

	function initInfo(data) {
		if (data.code == 0) {
			result = data.data;
			$("#id").val(result.id);
			$("#username").val(result.username);
			$("#realname").val(result.realname);
			$("#email").val(result.email);
			$("#phone").val(result.phone);
			$("#useStatus").val(result.useStatus);
		} else {
			$("#msg").text(data.msg + "[" + data.code + "]");
		}
	}

	function setParams() {
		params.id = $("#id").val();
		params.username = $("#username").val();
		params.realname = $("#realname").val();
		params.email = $("#email").val();
		params.phone = $("#phone").val();
		params.useStatus = $("#useStatus").val();
		params.encryptKey = $("#encryptKey").val();
	}

	function suss(data) {
		init();
		if (data.code == 0) {
			result = data.data;
			$("#msg").text(data.msg + "[" + data.code + "]");
		} else if (data.code == 4003) {
			$("#msg").text(data.msg + "[" + data.code + "]");
			setError(data);
		} else {
			$("#msg").text(data.msg + "[" + data.code + "]");
		}
	}

	function setError(data) {
		var error = data.data;
		$("#error_username").text(error.username);
		$("#error_realname").text(error.realname);
		$("#error_email").text(error.email);
		$("#error_phone").text(error.phone);
		$("#error_useStatus").text(error.useStatus);
		$("#error_encryptKey").text(error.encryptKey);
	}

	function err(data) {
		$("#msg").text("网络错误(" + data.status + ")")
	}

	function save() {
		setParams();
		post("/admin/save", params, suss, err);
	}
</script>
</head>
<body>
	<h1>
		<a href="select.html">管理员信息</a>
	</h1>

	<h4 id="msg"></h4>
	<div id="info">
		<input id="id" type="hidden" value=""></input>
		<table>
			<tr>
				<td>登录名:</td>
				<td><input id="username" type="text"></input></td>
				<td><strong id="error_username"></strong></td>
			</tr>
			<tr>
				<td>昵称:</td>
				<td><input id="realname" type="text"></input></td>
				<td><strong id="error_realname"></strong></td>
			</tr>
			<tr>
				<td>邮箱:</td>
				<td><input id="email" type="text"></input></td>
				<td><strong id="error_email"></strong></td>
			</tr>
			<tr>
				<td>手机:</td>
				<td><input id="phone" type="number"></input></td>
				<td><strong id="error_phone"></strong></td>
			</tr>
			<tr>
				<td>可用状态:</td>
				<td><input id="useStatus" type="number" max="1" min="0"></input></td>
				<td><strong id="error_useStatus"></strong></td>
			</tr>
			<tr>
				<td><input id="save" type="button" onclick="save()" value="保存"></input></td>
			</tr>
		</table>
	</div>
</body>
</html>